package com.party.core.service.member.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.member.MemberPersonalCountReadDao;
import com.party.core.dao.write.member.MemberPersonalCountWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.member.MemberPersonalCount;
import com.party.core.service.member.IMemberPersonalCountService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @Description: 会员个人数据统计service
 * @Author: yangshoukun
 * @Date: 2018/2/28 15:02
 */
@Service
public class MemberPersonalCountService implements IMemberPersonalCountService {

    @Autowired
    private MemberPersonalCountWriteDao memberPersonalCountWriteDao;

    @Autowired
    private MemberPersonalCountReadDao memberPersonalCountReadDao;

    @Override
    public String insert(MemberPersonalCount memberPersonalCount) {
        BaseModel.preInsert(memberPersonalCount);
        boolean result = memberPersonalCountWriteDao.insert(memberPersonalCount);
        if (result) {
            return memberPersonalCount.getId();
        }
        return null;
    }

    @Override
    public boolean update(MemberPersonalCount memberPersonalCount) {
        return memberPersonalCountWriteDao.update(memberPersonalCount);
    }

    /**
     * 逻辑删除
     * @param id 实体主键
     * @return
     */
    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return memberPersonalCountWriteDao.deleteLogic(id);
    }

    /**
     * 实际删除
     * @param id 实体主键
     * @return
     */
    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return memberPersonalCountWriteDao.delete(id);
    }

    /**
     * 批量删除
     * @param ids 主键集合
     * @return
     */
    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return memberPersonalCountWriteDao.batchDeleteLogic(ids);
    }

    /**
     * 批量物理删除
     * @param ids 主键集合
     * @return
     */
    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return memberPersonalCountWriteDao.batchDelete(ids);
    }

    @Override
    public MemberPersonalCount get(String id) {
        return memberPersonalCountReadDao.get(id);
    }

    @Override
    public List<MemberPersonalCount> listPage(MemberPersonalCount memberPersonalCount, Page page) {
        return memberPersonalCountReadDao.listPage(memberPersonalCount, page);
    }

    @Override
    public List<MemberPersonalCount> list(MemberPersonalCount memberPersonalCount) {
        return this.listPage(memberPersonalCount, null);
    }

    @Override
    public List<MemberPersonalCount> batchList(Set<String> ids, MemberPersonalCount memberPersonalCount, Page page) {
        return null;
    }

    @Override
    public MemberPersonalCount getByPartnerMemberId(String partnerMemberId) {
        List<MemberPersonalCount> list = memberPersonalCountReadDao.getByPartnerMemberId(partnerMemberId);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.get(0);
    }
}
